#include "itemoperatordelegate.h"
#include <QToolBar>
#include <QToolButton>
#include <QMessageBox>
#include "ItemOperator/itembutton.h"

ItemOperatorDelegate::ItemOperatorDelegate(QWidget *parent): QItemDelegate(parent)
{
}

QWidget *ItemOperatorDelegate::createEditor(QWidget *parent,
     const QStyleOptionViewItem &option,
     const QModelIndex &index) const
{
    QToolBar* toolbar = new QToolBar("", parent);
    ItemButton *modify = new ItemButton(parent);
    ItemButton *del = new ItemButton(parent);

    modify->setIcon(QIcon(":/images/modify.png"));
    del->setIcon(QIcon(":/images/delete.png"));

    toolbar->addWidget(modify);
    toolbar->addWidget(del);

    del->id = modify->id = index.sibling(index.row(), 4).data().toInt();

    QObject* p = parent;
    QObject* p1 = p;
    while (p != NULL)
    {
        p1 = p;
        p = p->parent();
    }

    connect(modify, SIGNAL(clicked()), p1, SLOT(onItemModify()));
    connect(del, SIGNAL(clicked()), p1, SLOT(onItemDelete()));

    return toolbar;
}

